package org.dormi.learn;

import audit.AuditLog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

public class Log2kafka {

    private static final Logger log = LoggerFactory.getLogger(Log2kafka.class);

    static {
        System.setProperty("sun.net.spi.nameservice.nameservers","192.168.18.31");
        System.setProperty("sun.net.spi.nameservice.provider.1","dns,sun");
    }

    public static void main(String[] args) throws Exception {

        MDC.put("request_id", "request_id");
        MDC.put("operator_id", "operator_id");
        MDC.put("operator_name", "operator_name");
        MDC.put("operation_time_start", "operation_time_start");
        MDC.put("operation_time_cost", "operation_time_cost");
        MDC.put("operator_ip", "operator_ip");
        MDC.put("scenario", "scenario");
        MDC.put("serviceName", "service_A".toLowerCase());

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String t = sdf.format(new Date());

        log.info("hello, {} {}", "world", t);
        AuditLog.info("hello, world " + t);

        TimeUnit.SECONDS.sleep(3);
    }
}
